"use strict";

/**
 * @name /
 * @param int sid 当前登录服务器ID
 * @param string access 认证信息
 * 服务器端登录认证
 */

module.exports = async function () {
    let sid = this.get('sid', 'int') || 0;
    let access = this.get('access', 'string');
    if (!sid || !access) {
        return this.error('args empty');
    }

    let developModel = this.model.redis("develop", this.branch);
    let _isDev = await developModel.get(access);
    if (!_isDev) {
        //非开发者的话，检查区服状态
        let keys = ["online", "status"];
        let query = {};
        let option = {"dataType": "json"};
        let server = this.model.branch("server", this.branch);
        option["fields"] = server.fields(keys);
        query['_id'] = sid;
        let _server = await server.find(query, option);
        if (_server && (_server.status != 1)) {
            return this.error('游戏维护中！', 'need develop auth');
        }
        // console.log(`isDev:${_isDev}`);
        // console.log(_servers);
    }


    let openid = this.model.branch("openid", this.branch);
    let _ret = await openid.verify(access, sid);
    return _ret;
};
